package com.lingxu.api.ztb.controller;


import com.lingxu.api.ztb.model.ViewProjectInvestment;
import com.lingxu.api.ztb.service.IFeasibilityReviewMeetingService;
import com.lingxu.api.ztb.service.IProjectInfoService;
import com.lingxu.api.ztb.model.ProjectInfo;
import com.lingxu.api.ztb.model.vo.ProjectInfoVO;
import com.lingxu.api.ztb.service.IViewProjectInvestmentService;
import com.lingxu.api.ztb.service.IZtbProjectService;
import com.lingxu.traffic.service.ProjectService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.common.api.vo.ResultOne;
import com.lingxu.base.common.annotation.Encrypt;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.util.*;

/**
 * 项目信息表 前端控制器
 *
 * @author admin
 * @since 2025-08-13
 */
@Slf4j
@Api(tags = "项目信息表", value = "ProjectInfoController")
@Validated
@CrossOrigin
@RestController
@RequestMapping("/projectInfo")
public class ProjectInfoController {

    @Autowired
    private IProjectInfoService  projectInfoService;

    @Autowired
    private IZtbProjectService iZtbProjectService;

    @Autowired
    private ProjectService projectService;

    @Autowired
    private IViewProjectInvestmentService viewProjectInvestmentService;

    @Autowired
    private IFeasibilityReviewMeetingService feasibilityReviewMeetingService;
    /**
    * 分页查询
    *
    * @param query
    * @return
    */
    @ApiOperation(value="项目信息表列表")
    @PostMapping(value = "/list")
    public ResultOne<ProjectInfoVO> queryPageList(@RequestBody ProjectInfoVO query) {
        return ResultOne.ok(projectInfoService.queryPageList(query));
    }

    @GetMapping("/detail")
    public Result<List<Map<String, Object>>> getProjectDetail (@RequestParam ("projectName") String projectName){
        ProjectInfo projectDetail = projectInfoService.getProjectDetail(projectName);
//        String approvalDate = feasibilityReviewMeetingService.getApprovalDate(projectName);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("项目名称", projectDetail.getProjectName());
        hashMap.put("实施主体",projectDetail.getUnit());
        hashMap.put("立项时间",projectDetail.getApprovalDate());
        hashMap.put("建设状态",projectDetail.getConstructionStatus());
        hashMap.put("总投资（亿）",projectDetail.getTotalInvestment());
        hashMap.put("建设标准",projectDetail.getConstructionStandard());
        hashMap.put("规模（公里）",projectDetail.getProjectScale());
        hashMap.put("标段总数",projectDetail.getBDNUMBER());
        hashMap.put("已完成投资额",projectDetail.getYWCTZE());
        hashMap.put("项目进度",projectDetail.getProjectProgress());

        return Result.ok(hashMap);
    }

    /**
     * 保存
     *
     * @param vo
     * @return
     */
    @ApiOperation(value = "项目信息表新增")
    @PutMapping(value = "/add")
    public Result<?> add(@Encrypt @RequestBody ProjectInfo vo) {
        projectInfoService.save(vo);
        return Result.ok("添加成功！");
    }

    // 查询国省干线 项目名称，项目进度
    @GetMapping("/gsgxprogress")
    public Result<List<Map<String, Object>>> getGsgxProjectProgressList() {
        List<Map<String, Object>> progressList = projectInfoService.getGsgxProjectProgressList();
        for (Map<String, Object> progress : progressList) {
            progress.put("项目编号", progress.get("XMBH"));
            progress.put("项目名称", progress.get("XMMC"));
            progress.put("项目进度", progress.get("XMJD"));
            progress.remove("XMBH");
            progress.remove("XMMC");
            progress.remove("XMJD");
        }
        return Result.ok(progressList);
    }

    /**
    * 修改
    *
    * @param vo
    * @return
    */
    @ApiOperation(value = "项目信息表修改")
    @PostMapping(value = "/edit")
    public Result<?> edit(@Encrypt @RequestBody ProjectInfo vo) {
        projectInfoService.updateById(vo);
        return Result.ok("编辑成功!");
    }

    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "项目信息表查询详情")
    @GetMapping("/get")
    public Result<ProjectInfoVO> get(@RequestParam String id){
        return  Result.ok(projectInfoService.getById(id));
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public Result<String> delete(@Encrypt @RequestBody Set<String> ids){
        projectInfoService.delete(ids);
        return Result.ok("删除成功!");
    }

}
